/**
 * Created by qian.zhou on 2017/2/23.
 */

var React = require('react');

var Icon = require('../components/Icon');
var ajax= require('../tools/ajax');

module.exports = React.createClass({
    getInitialState:function(){
        return {
            loveGoods:[],//所在类型的商品信息
            flag:false
        }
    },
    componentDidMount:function(){
        this.getLoveGoods();
    },
    proInfo: function (e){
        var action = e.currentTarget.getAttribute("action");
        var id = e.currentTarget.getAttribute("data");
        var price = e.currentTarget.getAttribute("data-price");
        localStorage.setItem("back","#fenlei");
        localStorage.setItem("price",price);
        location.href = "#goodDetail/"+id;
    },
    getLoveGoods(){
        var p = this;
        ajax("POST","getLoveGoods",{},function(dt){
            if(dt && dt.success){
                var objs = dt.data;
                console.log(objs);
                p.setState({loveGoods:objs});
            }
        });
    },
    render:function(){
        var p = this;
        var loveGoodsList = p.state.loveGoods.map(function(obj,index){
            return (
                <div key={index} className="item" onClick={p.proInfo} data={obj.id} data-price={obj.ProPrice}>
                    <div className="pro-img">
                        <img src={obj.goods_img.split(",")[0]}/>
                    </div>
                    <div className="pro-msg">
                        <p className="item_title">{obj.goods_name}</p>
                    </div>
                    <div className="pro-add">
                        <div className="pro_price">
                            ￥{obj.ProPrice}
                        </div>
                        <Icon icon="#icon-gouwuche-tianjia" style={{color:"#999",fontSize:"1rem"}}></Icon>
                    </div>
                </div>
            )
        });
        return (
            <div className="gj-pro">
                <div className="item more" onClick={p.more} style={{display:p.state.flag?"block":"none"}} data-countryid={this.props.countryid}>
                    <Icon icon="#icon-fanhui" style={{fontSize:"3rem"}}/>
                </div>
                {loveGoodsList}
            </div>
        )
    }
});